<extend name="Public/base" />
<block name="content">
<div id="content">
	<div id="content-header">
		<div id="breadcrumb">
			<a class="tip-bottom" href="{:U('Index/index')}" data-original-title="首页"><i class="icon-home"></i> 首页</a>
			<a class="current" href="{$post_url}">{$meta_title}</a>
		</div>
	</div>
	<div class="container-fluid">
		<br/>
		<if condition="$activity_id eq 0">
			<span class="control-group">
				<select class="form-control" style="width: 120px;" name="activity_select" id="activity_select" autocomplete="off" onchange="change_present(activity_select)">
					<option value="0">请选择活动</option>
					<volist name="activity_list" id="vo">
						<option value='{$vo.activity_id}'>{$vo.activity_name|strip_tags}</option>
					</volist>
				</select>
			</span>
		<else/>
			<h2 class="fl">{$activity_id|getActivityName}</h2>
		</if>
		
		<div class="row-fluid">
			<div class="span12">
				<div class="widget-box">
					<div class="widget-title">
						<span class="icon"> <i class="icon-align-justify"></i></span>
						<h5>{$meta_title}</h5>
					</div>

					<div class="widget-content nopadding">
						<form class="form-horizontal" autocomplete="off">
							<div class="control-group">
								<label class="control-label"><button class="btn btn-info btn-focus" type="button" >扫描纸质订单</button></label>
								<div class="controls" style="padding-top:15px;">
									<input type="text" placeholder="扫描／输入纸质订单" class="ui-wizard-content" name="paper_order" id="paper_order" onfocus="paper_order_clear();" onkeypress='enterOrderPress(event)'>
									<span class="help-block blue" id="order_number_help" style="margin-top:10px; font-size:16px;"></span> 
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" style="padding-top:10px; line-height:24px;">礼品 :</label>
								<div class="controls" id="present_id">
									<volist name="present_id_list" id="val">
										<label style="float:left; margin-right:30px;">
								    		<input type="radio" name="present_id" value="{$key}">{$val}
								  		</label>
									</volist>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">数量 :</label>
								<div class="controls">
									<input type="text" maxlength="3" class="ui-wizard-content span2" style="width:40px; text-align:center;" name="gift_num" value="1" id="gift_num" onkeyup="javascript:CheckInputIntFloat(this);" onkeypress="print_submit(event)">
								</div>
							</div>
							<div class="form-actions">
								<input type="hidden" value="{$activity_id}" name="activity_id" id="activity_id">
								<button class="btn btn-success" type="button" id="pay">确认换礼</button>
							</div>
						</form>	
					</div>
					
				</div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
//活动下礼品
function change_present(activity_select){
	var activity_select = parseInt($(activity_select).val());
	$('#present_id').html('');//礼品ID，内容为空
	if(activity_select > 0){
		$('input').attr('disabled', false);//选择活动后，activity_select大于0时，input可操作
		$('#activity_id').val(activity_select);
		$.post("{:U('OrderGift/getPresentId')}",{activity_id : activity_select},function(backData){
			//商户选项
			var option = '';
			if(backData.status == 1){
				$.each(backData.data,function(index,array){
					option += '<label style="float:left; margin-right:30px;"><input type="radio" style="margin-right:5px; margin-bottom:5px" name="present_id" value="'+index+'">'+array+'</label>';
				})
			}
			$('#present_id').append(option);//追加礼品ID中的选项内容
			$('#paper_order').focus();//选择活动后，光标转到订单文本框
		})
	}else{
		$('input').attr('disabled', true);//选择活动后，activity_select不大于0时，input不可操作
	}
}

//纸质订单 - 键盘按键被按下并释放一个键时发生
function enterOrderPress(e){
	var e = e || window.event;
	if(e.keyCode == 13){
		var paper_order = $.trim($('#paper_order').val());
		var activity_id = $.trim($('#activity_id').val());
		$.post("{:U('OrderGift/searchOrder')}", {paper_order:paper_order,activity_id:activity_id}, function(data) {
			if (data.status == 1) {
				var obj = data.data;
				var str = '';
					str += '<div class="copy_model" style="margin-bottom:5px;">';
					str += '纸质订单号：' + obj.paper_order + '｜金额：' + obj.order_amount + '｜用户：' + obj.customer_id + '｜品类：' + obj.conf_category + '｜' + obj.paper_gift_status;
//					str += '纸质订单号：<input type="text" value="' + obj.paper_order + '" id="next_focus" style="width:50px;" readonly>｜金额：' + obj.order_amount + '｜用户：' + obj.customer_id + '｜品类：' + obj.conf_category + '｜' + obj.paper_gift_status;
					str += '</div>';
				$('#order_number_help').html(str);
				$('#gift_num').focus();
			}else{
				$('#order_number_help').html('');
				tke_alert(data.info, 'alert-error', 10000);
			}
			return false;
		}, "json"); 
	}
}

//获取焦点时触发 
function paper_order_clear(){
	$('#paper_order').select();
	$('#order_number_help').html('');
}

//数量
function CheckInputIntFloat(oInput){
    if('' != oInput.value.replace(/\d{1,}\.{0,1}\d{0,}/,'')){
        oInput.value = oInput.value.match(/\d{1,}\.{0,1}\d{0,}/) == null ? '' :oInput.value.match(/\d{1,}\.{0,1}\d{0,}/);
    }
}
function print_submit(e){
	var e = e || window.event;
	if(e.keyCode == 13){
		$('#pay').trigger('click');
	}
}

//当文档载入时执行function函数里的代码
$(document).ready(function(){
	//焦点纸质订单号
	$('#paper_order').focus();
	
	//点击扫描纸质订单清空订单号记录
	$('.btn-focus').click(function(){
		$(this).parent().parent().find('input').val('').focus();//焦点获取
	})
	
	//提交订单
	$("#pay").click(function(){
		if(!confirm('是否确定换礼？')){
			return false;
		}
		//锁定登录按钮
		$('button').attr('disabled',true);
		$.post("{:U('OrderGift/add')}", $('form').serialize(), call_back, "json");
		return false;
		function call_back(data){
			if(data.status == 1){
				tke_alert(data.info,'alert-success');
				setTimeout(function(){
				  if (data.url) {
						location.href=data.url;
					}else{
						location.reload();
					}
				},1500);
			} else {
				tke_alert(data.info, 'alert-error', 15000);
			}
			$('button').attr('disabled',false);
		}
	});
	//导航高亮
	highlight_subnav("{:U('OrderGift/add')}");
});
</script>
</block>